<?php include template('header','admin');?>
<form action="<?php echo url('add') ?>" method="POST" name="form-validate">
<div class="fixed-nav layout">
	<ul>
		<li class="first">添加商家账号<a id="addHome" title="添加到首页快捷菜单">[+]</a></li>
		<li class="spacer-gray"></li>
	</ul>
	<div class="hr-gray"></div>
</div>
<div class="content padding-big have-fixed-nav">
	<div class="form-box clearfix">
		<?php echo Form::input('text', 'name', '', '账号名称：', '设置商家账号名称',array('datatype' => '*')); ?>
        <?php echo Form::input('password', 'password', '', '密码：', '设置商家账号登录密码', array('validate'=>'required;')); ?>
		<div class="form-group" style="z-index: 2;">
		        <span class="label">所属商家：</span>
		        <div class="box" style="width: 256px;">
	                <div class="form-select-edit select-search-text-box">
	                    <div class="form-buttonedit-popup">
	                        <input class="input" type="text" value="<?php echo $info['brandname']?>" readonly="readonly" data-reset="false">
	                        <span class="ico_buttonedit"></span>
	                        <input type="hidden" name="brand_id" value="<?php echo $info['brand_id']?>" data-reset="false">
	                    </div>
	                    <div class="select-search-field border border-main">
                    		<input class="input border-none" autocomplete="off" type="text" id="brandname" value="" placeholder="请输入品牌名称" data-reset="false" />
                    		<i class="ico_search"></i>
                    	</div>
	                    <div class="listbox-items brand-list">
	                    <?php foreach ($info['extra'] AS $brand) {?>
	                    	<span class="listbox-item" data-val="<?php echo $brand['id']?>"><?php echo $brand['name']?></span>
	                    <?php }?>
	                   </div>
	                </div>
		        </div>
		        <p class="desc">为商品选择所属品牌，便于用户按照品牌进行查找</p>
		</div>
		<?php echo Form::input('text', 'min_points', '', '最小经验值：', '设置会员等级所需要的最低经验值下限',array('datatype' => 'n')); ?>
		<?php echo Form::input('text', 'max_points', '', '最大经验值：', '设置会员等级所需要的最高经验值上限',array('datatype' => 'n')); ?>
		<?php echo Form::input('text', 'discount', '', '折扣率：', '折扣率单位为%，如输入90，表示该会员等级的用户可以以商品原价的90%购买',array('datatype' => 'n')); ?>
		<?php echo Form::input('textarea', 'description', '', '等级描述：','会员等级描述信息'); ?>
	</div>
	<div class="padding">
		<input type="submit" name="dosubmit" class="button bg-main" value="确定" />
		<input type="reset" name="back" class="button margin-left bg-gray" value="返回" />
	</div>
</div>
</form>
<script type="text/javascript" src="./statics/js/haidao.validate.js?v=5.3.2" ></script>
<script>
	$('.form-group:last-child').addClass('last-group');

		$('.select-search-field').click(function(e){
			e.stopPropagation();
		});
		//buttonedit-popup-hover
		$('.select-search-text-box .form-buttonedit-popup').click(function(){
			if(!$(this).hasClass('buttonedit-popup-hover')){
				$(this).parent().find('.select-search-field').show();
				$(this).parent().find('.select-search-field').children('.input').focus();
				$(this).parent().find('.listbox-items').show();
			}else{
				$(this).parent().find('.select-search-field').hide();
				$(this).parent().find('.listbox-items').hide();
			}
		});
		$('#brandname').live('keyup',function(){
			var url = "<?php echo url('ajax_brand')?>";
			var brandname = this.value;
			$.post(url,{brandname:brandname},function(data){
				$('.brand-list').children('.listbox-item').remove();
				if(data.status == 1){
					var html = [];
					$.each(data.result,function(i,item){
						 html.push('<span class="listbox-item" data-val="' + i + '">' + item + '</span>');
					})
					$('.brand-list').append(html.join(''));
				}else{
					var html = '<span class="listbox-item">未搜索到结果</span>';
					$('.brand-list').append(html.join(''));
				}
			},'json')
		})
		$(".select-search-text-box .listbox-items .listbox-item").live('click',function(){
			$(this).parent().prev('.select-search-field').children('.input').val();
			$(this).parent().prev('.select-search-field').hide();
			$('.select-search-text-box .form-buttonedit-popup .input').val($(this).html());
			$('input[name=brand_id]').val($(this).attr('data-val'));
		});
</script>

</body>
</html>

<script type="text/javascript">
$(function() {
	var validate = $("[name=form-validate]").Validform({
		ajaxPost:true,
		callback:function(ret) {
			message(ret.message);
			if(ret.status == 1) {
				setTimeout(function(){
					window.top.main_frame.location.href= ret.referer;
				}, 1000);
			} else {
				return false;
			}
		}
	});
})
</script>